var readstatus = {
    init : function($ele,options){
        var me = $ele;
        var opt = options || {};

        this.setReadStatus(opt);
        this.initReadedStyle(me)

    },

    //opt = {type:xxx,id:xxx}
    setReadStatus : function(opt){

        var readT = 'T'+ opt.type;
        var readID = opt.id;
        var localReadD;

        //如果localStorage没有READ_D
        if (!localStorage.getItem('READ_D')) {
            READ_FLAG[readT] = [];
            READ_FLAG[readT].push(readID);

            //存取最开始点击的数据到localStorage
            localStorage.setItem('READ_D', JSON.stringify(READ_FLAG));
        }else{

            //获取最新localStorage的READ_D信息
            localReadD = JSON.parse(localStorage.getItem('READ_D'));

            //获取对应的type数组
            var readTypeArr = localReadD[readT];

            //如果有当前点击的type数组
            if(readTypeArr){

                //判断当前点击的id是否在数组中
                var inRead = $.inArray(readID,readTypeArr);

                //如果没有
                if(inRead == -1){

                    //限定存取的最大条数,超出删除第一条
                    if(readTypeArr.length >= 30){
                        readTypeArr.shift();
                    }
                    readTypeArr.push(readID);
                    //console.log(readTypeArr);
                    //更新localStorage
                    localStorage.setItem('READ_D', JSON.stringify(localReadD));
                }

                //如果没有当前点击对应的数组
            }else{
                //取得最新localStorage并创建对应的数组
                localReadD = JSON.parse(localStorage.getItem('READ_D'));
                localReadD[readT] = [];
                localReadD[readT].push(readID);
                //更新localStorage
                localStorage.setItem('READ_D', JSON.stringify(localReadD));
            }
        }
    },

    //$items is selector
    initReadedStyle : function($items){
        var _this = this;
        $items.each(function(index,item){
            if(_this.checkReadStatus($(item).attr('data-type'),$(item).attr('data-id'))){
                $(item).find('p').css('color','#939393');
            }
        })
    },

    checkReadStatus:function(type,id){
        var getReadD = JSON.parse(localStorage.getItem('READ_D'));
        var t = 'T'+ type;

        return (getReadD && getReadD[t] && $.inArray(id,getReadD[t]) != -1) ? true : false;
    }
}